<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue,getEditorTitle,configMultiSelectData} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				resourceInstIdCacheKey:"obj-year-tinstAnnualTargetPlan-title_resource-resourceInstId-cache",
				work1Cache:"obj-year-tinstAnnualTargetPlan-title_resource-work1-cache",
				workCache:"obj-year-tinstAnnualTargetPlan-title_resource-work-cache"
			})
		},
		methods:{
			initLoad(e){
				let _that = this
				let pro1 = _that.om.request("dictZero/getListByCode",{code:'33200'})
				let pro2 = _that.om.request("tsysdict/getComboTree",{code:'30051',layer:'2'})
				let pro3 = _that.om.request("tsysdict/getListByCode",{code:'30061'})
				let pro4 = _that.om.request("dictZero/getListByCode",{code:'35803'})
				let pro5 = _that.om.request("orgInstPosUserOfficial/findListByInstId",{instId:e.instId})
				Promise.all([pro1,pro2,pro3,pro4,pro5]).then(res=>{
					_that.$refs.autoform.changeEditor("title_resource","itemCateCode","data",configSelectData(res[0],"code","dicname"))
					_that.$refs.autoform.initSelectIndex("title_resource","itemCateCode")
					_that.$refs.autoform.changeEditor("title_resource","unitId","type","multipicker")
					_that.$refs.autoform.changeEditor("title_resource","unitId","data",configMultiSelectData(res[1],"id","text"))
					_that.$refs.autoform.changeEditor("title_resource","unitId","initValueField","id")
					_that.$refs.autoform.changeEditor("title_resource","unitId","initNameField","text")
					_that.$refs.autoform.changeEditor("title_resource","moneyUnitId","data",configSelectData(res[2],"id","dicname"))
					_that.$refs.autoform.initSelectIndex("title_resource","moneyUnitId")
					_that.$refs.autoform.changeEditor("title_resource","monthCode","data",configSelectData(res[3],"code","dicname"))
					_that.$refs.autoform.initSelectIndex("title_resource","monthCode")
					_that.$refs.autoform.changeEditor("title_resource","resourceOffId","data",configSelectData(res[4],"id","userPosName"))
					_that.$refs.autoform.initSelectIndex("title_resource","resourceOffId")
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.workCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.workCode = d.orderNum
							uni.removeStorage({
								key:_that.workCache
							})
						}
					}
				});
				uni.getStorage({
					key:_that.resourceInstIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.resourceInstId = d.id
							formdata.resourceInstName = d.text
							uni.removeStorage({
								key:_that.resourceInstIdCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							_that.initLoad(e)
								uni.setStorage({
									key: _that.work1Cache,
									data:JSON.parse(e.workList),
									success: (res) => {
										
										let title = getEditorTitle("title_resource", "workCode",_that.autoformdata)
										changeEditor("title_resource", "workCode", {
											link: "../../public/search/search",
											"linkParam": {
												other: JSON.stringify({}),
												cachename: _that.workCache,
												otherCache: _that.work1Cache,
												defaultData: true,
												initload: true,
												namefield: "orderNum",
												extrafield: 'workName',
												placeholder: "请输入" + title
											}
										},null,_that.autoformdata)
										
										changeEditor('title_resource','resourceInstId',{
											link: '../../public/search/search',
											linkParam: {
												namefield: 'text',
												searchfield:'q',
												initload:true,
												url: "tinstitution/getComboTree",
												cachename: _that.resourceInstIdCacheKey,
												placeholder: '请输入岗位名称',
											}
										}, null, _that.autoformdata);
									}
								})
							}
						}
					})
				}
							
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
